unit UFormPesquisa;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RXDBCtrl,ToolEdit, StdCtrls, Buttons, ExtCtrls, Db, DBTables, Grids, DBGrids,
  Provider, SqlExpr, DBClient, DBLocal, DBLocalS;

type
  TFormPesquisa = class(TForm)
    Panel2: TPanel;
    BtnConsultar: TBitBtn;
    BtnLimpar: TBitBtn;
    BtnImprimir: TBitBtn;
    BtnSelecionar: TBitBtn;
    BtnFechar: TBitBtn;
    Panel1: TPanel;
    DSPesquisa: TDataSource;
    DBGrid1: TDBGrid;
    Panel3: TPanel;
    LRegistros: TLabel;
    SQLPesquisa: TSQLClientDataSet;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BtnConsultarClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure BtnImprimirClick(Sender: TObject);
    procedure BtnSelecionarClick(Sender: TObject);
    procedure BtnLimparClick(Sender: TObject);
  private
    { Private declarations }
    Comp :tcomponent;
    procedure ControlChange(Sender: TObject);
  public
    { Public declarations }
  end;

var
  FormPesquisa:TFormPesquisa;

implementation

uses UGeral;


{$R *.DFM}

procedure TFormPesquisa.BtnFecharClick(Sender: TObject);
begin
 addLog(2,self.Name,Usuario,TBitBtn(Sender).Caption + '; ' + TBitBtn(Sender).name,'');
 self.close;
end;

procedure TFormPesquisa.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 try
  SQLPesquisa.Close;
  self.Release;
 except
   addLog(10,self.Name,Usuario,'Form0close','Erro no fechamento do form');
 end;
end;

procedure TFormPesquisa.ControlChange(Sender : TObject);
begin
// marcacampo(Self,Comp,ActiveControl,clWindow,clTeal,clMenu);
 //marcacampo(Self,Comp,ActiveControl,clWindow,clMoneyGreen,clMenu);
end;

procedure TFormPesquisa.FormCreate(Sender: TObject);
var
 i :Integer;
begin
 SQLPesquisa.Close;
 Screen.OnActiveControlChange := ControlChange;
 BtnImprimir.Enabled:=false;
 BtnSelecionar.Enabled:=false;
 for i:=0 to ComponentCount - 1 do
  begin
   if Components[i] is TDateEdit then
    TDateEdit(Components[i]).EditMask:=MascaraData2;
  end;

end;

procedure TFormPesquisa.FormDestroy(Sender: TObject);
begin
  Screen.OnActiveControlChange := nil;
end;

procedure TFormPesquisa.BtnConsultarClick(Sender: TObject);
begin
 addLog(2,self.Name,Usuario,TBitBtn(Sender).Caption + '; ' + TBitBtn(Sender).name,'');
 DBGrid1.DataSource.Enabled:=True;
 BtnImprimir.Enabled:=DSPesquisa.DataSet.RecordCount <> 0;
 BtnSelecionar.Enabled:=(SQLPesquisa.RecordCount <> 0 )and (BtnSelecionar.Tag = 0) ;
 LRegistros.Caption:='Registros Encontrado(s) : ' + IntToStr(DSPesquisa.DataSet.RecordCount);
end;

procedure TFormPesquisa.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key = #13 then
 SelectNext(ActiveControl,true,true);

end;

procedure TFormPesquisa.BtnImprimirClick(Sender: TObject);
begin
 addLog(2,self.Name,Usuario,TBitBtn(Sender).Caption + '; ' + TBitBtn(Sender).name,'');
end;

procedure TFormPesquisa.BtnSelecionarClick(Sender: TObject);
begin
 addLog(2,self.Name,Usuario,TBitBtn(Sender).Caption + '; ' + TBitBtn(Sender).name,'');
end;

procedure TFormPesquisa.BtnLimparClick(Sender: TObject);
begin
 addLog(2,self.Name,Usuario,TBitBtn(Sender).Caption + '; ' + TBitBtn(Sender).name,'');
end;

end.
